//
//  DHOrderListViewModel.m
//  精品酒店
//
//  Created by DIANGHONG on 2018/5/10.
//  Copyright © 2018年 DIANGHONG. All rights reserved.
//

#import "DHOrderListViewModel.h"
#import "DHOrderListModel.h"
@implementation DHOrderListViewModel
- (void)loadOrderStatusListWithPullup:(BOOL)pullup page:(int)page
                               lng:(NSString *)lng
                               lat:(NSString *)lat
                         area_name:(NSString *)area_name
                             params:(NSDictionary *)params
                       FiniedBlock:(void(^)(BOOL isSuccess,BOOL shouldRefreshed))finiedBlock
{
    if (pullup) {
        if (!self.listModel) {return;}
        if (self.listModel.hasmore.boolValue) {
            page++;
        }else{
            finiedBlock(YES,false);
            return;
        }
    }
    [DHNetworkManager.shareManager requestHomeListWithPage:[NSString stringWithFormat:@"%d",page] lng:lng lat:lat area_name:area_name params:params
                                                completion:^(id json, BOOL isSuccess)
    {
        if (!isSuccess) {
            finiedBlock(isSuccess,false);
            return ;
        }
        if (json[@"datas"][@"error"]) {
            finiedBlock(YES,false);
            return;
        }
        if (pullup) {
            self.listModel = [DHOrderListModel yy_modelWithJSON:json];
            
            self.listModel.list = [self.listModel.list arrayByAddingObjectsFromArray:[NSArray yy_modelArrayWithClass:[DHOrderModel class] json:json[@"datas"][@"list"]]];
        }else{
        self.listModel = [DHOrderListModel yy_modelWithJSON:json];
   
        self.listModel.list = [NSArray yy_modelArrayWithClass:[DHOrderModel class] json:json[@"datas"][@"list"]];
        }
        finiedBlock(isSuccess,YES);
    }];
}

#pragma mark: - 加载清洁区域
- (void)loadClearAreaListWithKey:(NSString *)key
               FiniedBlock:(void(^)(BOOL isSuccess))finiedBlock
{
    [DHNetworkManager.shareManager loadClearAreaWithKey:key
                                             completion:^(id json, BOOL isSuccess)
    {
        if (!isSuccess) {
            finiedBlock(isSuccess);
            return ;
        }
        if (json[@"datas"][@"error"]) {
            finiedBlock(false);
            return;
        }
        
        self.clearAreaList = [NSArray yy_modelArrayWithClass:[DHClearArea class] json:json[@"datas"][@"list"]];
        finiedBlock(isSuccess);

    }];
}


@end
